﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using UnwiseSource.ServiceReference1;

namespace UnwiseSource
{
    public partial class lectures : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int courseId = 0;
            string language = (string)Session["language"];
            if (language != null && (int.TryParse(Request.QueryString["courseId"], out courseId) == true)) 
            {
                try
                {
                    Service1Client wsUnwiseSource = new Service1Client();
                    string SECID = Helper.getconfigparam("SECID", "");
                    LecturesAndHeader result = wsUnwiseSource.GetLecturesOfCourse(SECID, language, courseId);
                    if (result != null)
                    {
                        CreateLectures(result, language);
                    }
                    else
                    {
                        Response.Redirect("courses.aspx");
                    }
                }
                catch (Exception ex)
                {
                    Helper.LogErrorMsg(ex.ToString());
                }
            }
            else
            {
                Response.Redirect("courses.aspx");
            }
        }

        [WebMethod]
        public static string SaveLanguage(string lang)
        {
            HttpContext.Current.Session["language"] = lang;

            return lang;
        }

        public void CreateLectures(LecturesAndHeader response, string lang)
        {
            lectures_content.Controls.Clear();
            lectures_header.InnerText = response.CourseHeader;
            foreach (var item in response.Lectures)
            {
                string generatedHtml = GenerateHtml.GenerateLecture(item, lang);
                HtmlGenericControl link = new HtmlGenericControl("div");
                link.InnerHtml = generatedHtml;
                link.Attributes["onclick"] = "java(" + item.LectureId + ");";
                link.Attributes["id"] = "lecture_conteiner";
                lectures_content.Controls.Add(link);
            }
        }

        void link_ServerClick(object sender, EventArgs e)
        {
            int a = 5;
        }

        protected void ClickedOnALecture(object sender, EventArgs e)
        {

        }





    }
}